import { RegExpPwd } from '@vue-common/utils/validator'
export default () => {
  let obj = {
    // 表单数据
    data: {
      nickName: undefined,
      avatar: undefined,
      oldPwd: undefined,
      pwd: undefined,
      pwdRepead: undefined
    },
    // 表单标签
    label: {
      nickName: '用户昵称',
      avatar: '用户头像',
      oldPwd: '旧密码',
      pwd: '新密码',
      pwdRepead: '重复密码'
    },
    // 提示
    placeholder: {
      nickName: '请输入',
      oldPwd: '请输入',
      pwd: '请输入',
      pwdRepead: '请输入'
    },
    // 校验规则
    rule: {
      oldPwd: [
        {
          pattern: RegExpPwd,
          message: '密码必须8位以上同时包含字母和数字',
          trigger: 'blur'
        }
      ],
      pwd: [
        {
          pattern: RegExpPwd,
          message: '密码必须8位以上同时包含字母和数字',
          trigger: 'blur'
        }
      ],
      pwdRepead: [
        {
          pattern: RegExpPwd,
          message: '密码必须8位以上同时包含字母和数字',
          trigger: 'blur'
        },
        {
          trigger: 'blur',
          validator: (rule, value, callback) => {
            if (obj.data.pwd && value !== obj.data.pwd) {
              callback(new Error('两次输入的密码不一致'))
            } else {
              callback()
            }
          }
        }
      ]
    }
  }
  return obj
}
